package com.mapsolute.map24webservices15.clients.axis.wrappers;

import com.mapsolute.map24webservices15.clients.axis.stubs.*;

/**
* The Map24 Geocoder 5.1 Service is software for matching addresses to the 
* correct location (latitude and longitude) on the map. It is based on a 
* fuzzy text search and therefore can find addresses even if they are 
* incomplete or misspelled. Multiple rated search results are provided. 
* Such geocoding is needed in almost every mapping application for finding 
* spots on the map based on user input or for coding complete address 
* databases into the map.
*
* This is a wrapper class with static methods for the different ways to 
* issue Map24 Geocoder 5.1 Service requests. 
*/
public class Map24Geocoder51Wrapper 
{

	// ------------------------------------------------------------------------
	//  A d d r e s s
	// ------------------------------------------------------------------------
	/**
	 * Helper method for instantiating an Address object.
	 * 
	 * @param street          The street. 
	 * @param HouseNo         The house number.
	 * @param postalcode      The ZIP code.
	 * @param city            The city.
	 * @param country         The country.
	 * @return address        The Address object containing the given address data.
	 */
	public static Address Address(String street, String HouseNo, String postalcode, String city, String country)
	{
		Address address= new Address();
		
		address.setStreet(street);
		address.setHouseNo(HouseNo);
		address.setZIP(postalcode);
		address.setCity(city);
		address.setCountry(country);
		
		return address;
	}

    //------------------------------------------------------------------------
	//  G e t M a p 2 4 G e o c o d e r 5 1 P o r t
	// ------------------------------------------------------------------------

	/**
	 * Returns the port as specified for the Map24 Geocoder 5.1 Service in the WSDL.
	 *  
	 * @param binding 	    The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51". 
	 *                      If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
	 * @param map24id 	    The Map24 ID used for authentication.
	 * @param clientid 		  ID of the client that has initiated a request (SessionID).
	 * @return				      The port.
	 * @throws Exception
	 */
	public static Map24Geocoder51PortType GetMap24Geocoder51Port(String binding, String map24id, String clientid) throws Exception
	{ 	
		Map24Geocoder51Locator locator= new Map24Geocoder51Locator();
		
	   Map24Geocoder51PortType port= (binding == null) ? locator.getMap24Geocoder51Port() : locator.getMap24Geocoder51Port(new java.net.URL(binding+"&sid="+clientid));
		
		if (port instanceof Map24Geocoder51BindingStub)
		{
	        ((Map24Geocoder51BindingStub)port)._setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR,  Boolean.FALSE);
			((Map24Geocoder51BindingStub)port)._setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
			((Map24Geocoder51BindingStub)port)._setProperty(org.apache.axis.AxisEngine.PROP_SEND_XSI,    Boolean.FALSE);
		}
				
		return port;
				
	 } // GetMap24GeocoderPort
			
	
	
	// ------------------------------------------------------------------------
	//  S e a r c h  F r e e
	// ------------------------------------------------------------------------
	/**
	 * Geocodes an address given in a free text format (free search).
	 * 
	 * Returns the one or multiple alternative coordinates and the associated address data for the given address. 
	 * 
	 * @param binding 				The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51".                                                                    If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
	 * @param map24id 			    The Map24 ID used for authentication.
	 * @param clientid 				ID of the client that has initiated a request (SessionID).
	 * @param searchText			The address to be geocoded given in a free text format.
	 * @param maxNoOfAlternatives 	The maximum number of alternative search results (addresses) to be returned for the given address. 
	 * @return				        The response contains an array with one or multiple alternative addresses of type MapSearchAlternative. 
     *                              One MapSearchAlternative contains one address with associated coordinates that was found by the Map24 Geocoder 5.1.
	 */
	public static MapSearchResponse SearchFree(String binding, String map24id, String clientid, String searchText, int maxNoOfAlternatives)
	 {
		/////////////////////////////////////////////////////		
		// create MapSearchRequest
		/////////////////////////////////////////////////////		
	   		MapSearchFreeRequest request = new MapSearchFreeRequest();
	   		
	   		request.setSearchText(searchText);
	   		request.setMaxNoOfAlternatives(maxNoOfAlternatives);
	   		
	   
	   	
		/////////////////////////////////////////////////////		
		// create RequestHeader
		/////////////////////////////////////////////////////
		RequestHeader requestHeader = new RequestHeader();
		requestHeader.setMap24ID  (map24id);
		requestHeader.setClientID (clientid);
							
		try 
		{	return GetMap24Geocoder51Port(binding, map24id, clientid).searchFree(requestHeader, request);		
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
		return null;
			
	 } // SearchFree
	
    //------------------------------------------------------------------------
	//  S e a r c h  F r e e
	// ------------------------------------------------------------------------
	 /**
	 * Geocodes an address given in a free text format allowing additonal search properties in the request (hybrid search).
	 * 
	 * Additional search properties can for example be used to limit the possible result set to a certain map area. This search option is also called 
	 * hybrid search, since it leads to more accurate search results than the free search, while it allows to enter the address data in a free text format
	 * in contrast to the qualified address input required in the qualified search. 
	 *
	 * @param binding 				The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51". 
	 *                                                                    If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
	 * @param map24id 			 The Map24 ID used for authentication.
	 * @param clientid 				ID of the client that has initiated a request (SessionID).
	 * @param searchText			The address to be geocoded given in a free text format.
	 * @param maxNoOfAlternatives                       The maximum number of alternative search results (addresses) to be returned for the given address.
	 * @param properties			Optional additional search properties. For a list of search properties see the Map24 Geocoder 5.1 Service User's Guide. Can be null.
	 * @return			              The response contains an array with one or multiple alternative addresses of type MapSearchAlternative. 
	 *                                                                   One MapSearchAlternative contains one address with associated coordinates that was found by the Map24 Geocoder 5.1.
	 */		
	public static MapSearchResponse SearchFree(String binding, String map24id, String clientid, String searchText, int maxNoOfAlternatives, Property[] properties, MapSearchRequestSearchOption[] option)
	 {
		/////////////////////////////////////////////////////		
		// create MapSearchRequest
		/////////////////////////////////////////////////////		
	   		MapSearchFreeRequest request = new MapSearchFreeRequest();
	   		
	   		request.setSearchText(searchText);
	   		request.setMaxNoOfAlternatives(maxNoOfAlternatives);
	   		request.setProperties(properties);
	   		request.setOptions(option);
	   
	   	
		/////////////////////////////////////////////////////		
		// create RequestHeader
		/////////////////////////////////////////////////////
		RequestHeader requestHeader = new RequestHeader();
		requestHeader.setMap24ID  (map24id);
		requestHeader.setClientID (clientid);
							
		try 
		{	return GetMap24Geocoder51Port(binding, map24id, clientid).searchFree(requestHeader, request);		
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
		return null;
			
	 } // SearchFree
	   
    // ------------------------------------------------------------------------
	//  S e a r c h  F r e e
	// ------------------------------------------------------------------------
	/** 
     * Geocodes an address given in a free text format, optionally returning street crossings or housenumbers in the result set.
	 * 
	 * @param binding 			    The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51". 
	 *                              If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
	 * @param map24id 			    The Map24 ID used for authentication.
	 * @param clientid 			    ID of the client that has initiated a request (SessionID).
	 * @param searchText			The address to be geocoded given in a free text format.
	 * @param maxNoOfAlternatives   The maximum number of alternative search results (addresses) to be returned for the given address.
     * @param option                Optional parameter that can be used for specifying if housenumbers or crossings of the 
     *                              street should be returned in the result. Possible values are "Crossings" and "Housenumbers".
	 * @return                      The response contains an array with one or multiple alternative addresses of type MapSearchAlternative. 
	 *                              One MapSearchAlternative contains one address with associated coordinates that was found by the Map24 Geocoder 5.1.
	 */		
	public static MapSearchResponse SearchFree(String binding, String map24id, String clientid, String searchText, int maxNoOfAlternatives,MapSearchRequestSearchOption[] option)
	 {
		/////////////////////////////////////////////////////		
		// create MapSearchRequest
		/////////////////////////////////////////////////////		
	   		MapSearchFreeRequest request = new MapSearchFreeRequest();
	   		
	   		request.setSearchText(searchText);
	   		request.setMaxNoOfAlternatives(maxNoOfAlternatives);
	   		request.setOptions(option);
	   
	   	
		/////////////////////////////////////////////////////		
		// create RequestHeader
		/////////////////////////////////////////////////////
		RequestHeader requestHeader = new RequestHeader();
		requestHeader.setMap24ID  (map24id);
		requestHeader.setClientID (clientid);
							
		try 
		{	return GetMap24Geocoder51Port(binding, map24id, clientid).searchFree(requestHeader, request);		
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
		return null;
			
	 } // SearchFree   
	
    // ------------------------------------------------------------------------
	//  S e a r c h  Q u a l i f i e d
	// ------------------------------------------------------------------------
	/**
	 * Geocoding an address specified in search properties.
	 *  
	 * Returns the alternatives and the coordinates of an address.
	 * 
	 * @param binding 			    The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51". 
	 *                              If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
	 * @param map24id 	     	    The Map24 ID used for authentication.
	 * @param clientid 			    ID of the client that has initiated the request (SessionID).
	 * @param SearchProperties      Search properties to be geocoded.
	 * @param maxNoOfAlternatives   The maximum number of alternative search results (addresses) to be returned for the given address.
	 * @return		             	The response contains an array with one or multiple alternative addresses of type MapSearchAlternative. 
	 *                              One MapSearchAlternative contains one address with associated coordinates that was found by the Map24 Geocoder 5.1.
	 */		
	public static MapSearchResponse SearchQualified(String binding, String map24id, String clientid, Property[] SearchProperties, int maxNoOfAlternatives)
	 {
		/////////////////////////////////////////////////////		
		// create MapSearchRequest
		/////////////////////////////////////////////////////		
	   	MapSearchQualifiedRequest request = new MapSearchQualifiedRequest();
	   		
	   	request.setSearchProperties(SearchProperties);
	   	request.setMaxNoOfAlternatives(maxNoOfAlternatives);
	   		
	   
	   	
		/////////////////////////////////////////////////////		
		// create RequestHeader
		/////////////////////////////////////////////////////
		RequestHeader requestHeader = new RequestHeader();
		requestHeader.setMap24ID  (map24id);
		requestHeader.setClientID (clientid);
							
		try 
		{	return GetMap24Geocoder51Port(binding, map24id, clientid).searchQualified(requestHeader, request);		
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
		return null;
			
	 } // SearchFree
       
       
//	 ------------------------------------------------------------------------
	//  G e o c o d e A d d r e s s
	// ------------------------------------------------------------------------
	/**
	 * Geocodes an address given as Address object.
	 *
	 * @param binding 			      		The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51". 
	 *                                If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
	 * @param map24id                 The Map24 ID used for authentication.
	 * @param clientid                ID of the client that has initiated the request (SessionID).
	 * @param address                 The address of type Address to be geocoded.
	 * @param maxNoOfAlternatives     The maximum number of alternative search results (addresses) to be returned for the given address.
	 * @return                        The response contains an array of GeocodedAddress elements, one for each input address.  
     *                                Each GeocodedAddress element may contain from one up to maxNoOfAlternatives geocoded addresses 
     *                                of type GeocodedAddress.Alternative.
	 */
	public static GeocodeAddressesResponse GeocodeAddress(String binding, String map24id, String clientid, Address address, int maxNoOfAlternatives)
	 {
		/////////////////////////////////////////////////////		
		// create GeocodeRequest
		/////////////////////////////////////////////////////		
	   		GeocodeAddressesRequest request = new GeocodeAddressesRequest();
	   		
	   		request.setAddresses(new Address[] { address });
	   		request.setMaxNoOfAlternatives(maxNoOfAlternatives);
	   		
	   
	   	
		/////////////////////////////////////////////////////		
		// create RequestHeader
		/////////////////////////////////////////////////////
		RequestHeader requestHeader = new RequestHeader();
		requestHeader.setMap24ID  (map24id);
		requestHeader.setClientID (clientid);
							
		try 
		{	return GetMap24Geocoder51Port(binding, map24id, clientid).geocodeAddresses(requestHeader, request);		
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
		return null;
			
	 } // GeocodeAddress
	   
	   
	  /** 
     * Reverse geocodes addresses.
     * 
     * With the reverseGeocodeAddresses operation it is possible to search for surrounding map objects from the 
     * input of a single coordinate. This technique is often applied for retrieving textual descriptions for locations.
     *
     * At first the given coordinates are passed to the Map24 ReverseGeocoder Service for performing a search 
     * on the country, cty, street and ZIP code layers. With the returned names for the address fields 
     * a "common" geocode operation is performed. The house number is found by comparing all matchings
     * with the given Coordinate. Thus, depending on the accuracy of the input coordinate and the underlying map data, 
     * even a correct postal address can be returned.
     * 
     * @param binding 			The service that is used, for example ""http://maptp12.map24.com/map24/webservices1.5?soap=Map24Geocoder51". 
	   *                      If null, the server URL specified in the client stub Map24Geocoder51Locator is used.
     * @param map24id 			The Map24 ID used for authentication.
	   * @param clientid      ID of the client that has initiated the request (SessionID).
     * @param coordinates		The coordinates to search the corresponding addresses for. The Coordinate element has two subelements Longitude and Latitude.
     *											Note: The values of the Longitude and Latitude elements must comply to the WGS 84 format. 
     *											They are specified in decimal degrees and minutes.
     * @return        			GeocodeAddressesResponse contains the response of a reverseGeocodeAddresses request in the GeocodedAddresses array.
     *											The GeocodedAddresses array contains a GeocodedAddress element for each coordinate that was specified in the request.
     */
    public static GeocodeAddressesResponse ReverseGeocodeAddress(String binding, String map24id, String clientid, Coordinate[] coordinates)
	 {
 	   
 	   ReverseGeocodeAddressesRequest reverseGeocodeAddressesRequest = new ReverseGeocodeAddressesRequest();
 	   reverseGeocodeAddressesRequest.setCoordinates(coordinates);

 	   RequestHeader requestHeader = new RequestHeader();
        requestHeader.setMap24ID  (map24id);
        requestHeader.setClientID (clientid);
 	   
 	   try 
        {   
 		   return GetMap24Geocoder51Port(binding, map24id, clientid).reverseGeocodeAddresses(requestHeader, reverseGeocodeAddressesRequest); 
 		     
        }
        catch(Exception e)
        {
            System.err.println(e);
        }
        
        return null;
			
	 } // ReverseGeocodeAddress
		
	

       
		
} // Map24GeocoderWrapper
